package com.android.settings.ios;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;

import androidx.preference.Preference;

import com.android.settings.ios.view.OsPreferenceCategory;

public class CommonAppFragment extends BaseFragment {

    private String mPkgName;
    private OsPreferenceCategory mSiriCategory;

    @Override
    protected void onParseBundle(Bundle bundle) {
        super.onParseBundle(bundle);
        mPkgName = bundle.getString("packageName");
    }

    protected void onFindPreference() {
        mSiriCategory = findPreference("common_siri");
    }

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        addPreferencesFromResource(R.xml.common_app_fragment);
        onFindPreference();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mSiriCategory != null) {
            mSiriCategory.setTitle(getString(R.string.os_str_allow) + " \"" + mMainTitle + "\" " + getString(R.string.os_str_visit));
        }
    }

    @Override
    public boolean onPreferenceTreeClick(Preference preference) {
        final String key = preference.getKey();
        if ("app_details".equals(key) && mPkgName != null) {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.fromParts("package", mPkgName, null));
            getActivity().startActivity(intent);
            return true;
        }
        return super.onPreferenceTreeClick(preference);
    }
}
